from agent.session import Session


class SessionAdmin(object):
  def __init__(self):
    self.session_dict = {}
    self.session_id = 0
    self.global_id = 0

  def get_add_session_id(self):
    self.session_id = self.session_id + 1
    if self.session_id == 0:
      self.session_id = 1
    return self.session_id

  def add_session(self, s :Session):
    self.session_dict[s.get_key()] = s

  def del_session(self, s :Session):
    print('del session ', s)
    self.session_dict.pop(s.get_key())

  def get_session(self, key :str)->Session:
    return self.session_dict.get(key)
  
  def get_session_by_ids(self, global_id:int, session_id:int)->Session:
    return self.get_session(Session._get_key(global_id, session_id))